/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
define(["require", "exports", "../utils/convert"], function (require, exports, convert_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    class TypeScriptReferenceSupport {
        constructor(client, vscode) {
            this.client = client;
            this.vscode = vscode;
        }
        provideReferences(document, position, options, token) {
            return __awaiter(this, void 0, void 0, function* () {
                const filepath = this.client.normalizePath(document.uri);
                if (!filepath) {
                    return [];
                }
                const args = convert_1.vsPositionToTsFileLocation(filepath, position);
                try {
                    const msg = yield this.client.execute('references', args, token);
                    if (!msg.body) {
                        return [];
                    }
                    const result = [];
                    const has203Features = this.client.apiVersion.has203Features();
                    for (const ref of msg.body.refs) {
                        if (!options.includeDeclaration && has203Features && ref.isDefinition) {
                            continue;
                        }
                        const url = this.client.asUrl(ref.file);
                        const location = new this.vscode.Location(url, convert_1.tsTextSpanToVsRange(ref, this.vscode));
                        result.push(location);
                    }
                    return result;
                }
                catch (_a) {
                    return [];
                }
            });
        }
    }
    exports.default = TypeScriptReferenceSupport;
});
